package com.chief.hadoop.mr.outputFormat;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class FlowBean implements WritableComparable<FlowBean> {

    private Long total;
    private int cnt;

    public FlowBean() {
    }

    public int getCnt() {
        return cnt;
    }

    public void setCnt(int cnt) {
        this.cnt = cnt;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }


    @Override
    public int compareTo(FlowBean o) {
        if (o.getTotal().equals(this.getTotal())) {
            return o.getCnt() - this.getCnt();
        } else {
            return o.getTotal().compareTo(this.getTotal());
        }
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(total);
        out.writeInt(cnt);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.total = in.readLong();
        this.cnt = in.readInt();
    }

    @Override
    public String toString() {
        return this.getTotal() + "-----" + this.getCnt();
    }
}
